package com.zhang.passer.controller;

import com.alibaba.fastjson.JSON;
import com.zhang.passer.domain.CommentDao;
import com.zhang.passer.service.CommentService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @RequestMapping("/leave")
    public String leaveComment(CommentDao comment){
        return JSON.toJSONString(commentService.addComment(comment));
    }


    @RequestMapping("/get")
    public String leaveComment(@Param("bid") int bid,@Param("btype") String btype){
        List<CommentDao> comments = commentService.queryAllByBid(bid,btype);
        return JSON.toJSONString(comments);
    }
}
